home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / source / dialogs / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-02  |  4.0 KB  |  132 lines

  1. /*
  2.  * PRINT.C
  3.  *
  4.  * Code demonstrating the various uses of the PrintDlg common dialog.
  5.  *
  6.  * Copyright (c)1992 Microsoft Corporation, All Right Reserved
  7.  *
  8.  * Kraig Brockschmidt, Software Design Engineer
  9.  * Microsoft Systems Developer Relations
  10.  * One Microsoft Way
  11.  * Redmond, WA  98052
  12.  *
  13.  * Internet  :  kraigb@microsoft.com
  14.  * Compuserve:  70750,2344
  15.  * Fax       :  (206)936-7329
  16.  */
  17.  
  18. #include <windows.h>
  19. #include <commdlg.h>
  20. #include <dlgs.h>
  21. #include <memory.h>
  22. #include "dialogs.h"
  23.  
  24.  
  25.  
  26.  
  27.  
  28. /*
  29.  * PrintDialogs
  30.  *
  31.  * Purpose:
  32.  *  Invokes variations on the PrintDlg common dialog depending
  33.  *  on the menu selection.  For print, we use the hDC we get back
  34.  *  when the user chooses OK to print some text in the last font
  35.  *  selected in the fonts dialog (as held in the hgFont global).
  36.  *
  37.  * Parameters:
  38.  *  hWndOwner       HWND to use as the owner of the dialog.
  39.  *  iDialog         WORD indicating which dialog variation to invoke.
  40.  *
  41.  * Return Value:
  42.  *  BOOL            TRUE if OK was used in the dialog, FALSE otherwise.
  43.  */
  44.  
  45. BOOL PASCAL PrintDialogs(HWND hWndOwner, WORD iDialog)
  46.     {
  47.     PRINTDLG        pd;
  48.     BOOL            fRet=FALSE;
  49.     HFONT           hFontT=NULL;
  50.  
  51.  
  52.     /*
  53.      * Standard initialization:  NULL all fields in the structure,
  54.      * fill lStructSize, and set the owner window (the owner is
  55.      * strictly unecessary, but give the dialog its modal behavior
  56.      * like it should have).
  57.      */
  58.     memset(&pd, 0, sizeof(PRINTDLG));
  59.     pd.lStructSize=sizeof(PRINTDLG);
  60.     pd.hwndOwner=hWndOwner;
  61.  
  62.     switch (iDialog)
  63.         {
  64.         case IDM_PRINTPRINT:
  65.             /*
  66.              * These flags instruct the dialog to return a DC for the printer,
  67.              * select the All Pages radiobutton, check the Collate Copies
  68.              * checkbox, and disable the Print to File checkbox.
  69.              */
  70.             pd.Flags =PD_RETURNDC | PD_ALLPAGES | PD_COLLATE | PD_DISABLEPRINTTOFILE;
  71.  
  72.             pd.nCopies=1;       //Initial contents of the Copies edit control.
  73.             pd.nFromPage=1;     //Initial contents of the From edit control.
  74.             pd.nToPage=25;      //Initial contents of the To edit control.
  75.             pd.nMinPage=1;      //Lowest possible number in the From/To edits.
  76.             pd.nMaxPage=25;     //Highest possible number in the From/To edits.
  77.  
  78.             fRet=PrintDlg(&pd);
  79.  
  80.             if (fRet)
  81.                 {
  82.                 /*
  83.                  * Print something useless...note that this code
  84.                  * ignores trying to make the point size in the
  85.                  * font match the point size on the printed page.
  86.                  * This is simply to demonstrate that the hDC is
  87.                  * immediately available for printing.
  88.                  */
  89.                 if (NULL!=hgFont)
  90.                     hFontT=SelectObject(pd.hDC, hgFont);
  91.  
  92.                 Escape(pd.hDC, STARTDOC, 14, "PrintDlg Test", NULL);
  93.                 TextOut(pd.hDC, 50, 50, "My hovercraft is full of eels", 28);
  94.                 Escape(pd.hDC, NEWFRAME, 0, NULL, NULL);
  95.                 Escape(pd.hDC, ENDDOC, 0, NULL, NULL);
  96.  
  97.                 //Cleanup
  98.                 if (NULL!=hFontT)
  99.                     SelectObject(pd.hDC, hFontT);
  100.                 }
  101.             break;
  102.  
  103.  
  104.         case IDM_PRINTPRINTERSETUP:
  105.             /*
  106.              * Do Printer Setup only with PD_PRINTSETUP.  You can still
  107.              * retrieve the DC/IC from this with PD_RETURNDC or PD_RETURNIC.
  108.              */
  109.             pd.Flags=PD_RETURNIC | PD_PRINTSETUP;
  110.             fRet=PrintDlg(&pd);
  111.             break;
  112.         }
  113.  
  114.  
  115.     /*
  116.      * Cleanup:  Delete any DC or IC created by PrintDlg and free the
  117.      * allocated handles hDevMode and hDevNames.  The caller is responsible
  118.      * to perform this cleanup once it is finished using the DC or the data.
  119.      */
  120.  
  121.     if (NULL!=pd.hDC)
  122.         DeleteDC(pd.hDC);
  123.  
  124.     if (NULL!=pd.hDevMode)
  125.         GlobalFree(pd.hDevMode);
  126.  
  127.     if (NULL!=pd.hDevNames)
  128.         GlobalFree(pd.hDevNames);
  129.  
  130.     return fRet;
  131.     }
  132.